package com.hundredapp.oa.web.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import com.hundredapp.oa.domain.OaClass;
import com.hundredapp.oa.domain.OaContract;
import com.hundredapp.oa.domain.OaStudent;
import com.hundredapp.oa.repository.ClassmngManager;
import com.hundredapp.oa.repository.ContractManager;
import com.hundredapp.oa.vo.GraduationVO;
import com.opensymphony.xwork2.ActionSupport;

@Repository
@Scope("prototype")
public class Graduation extends ActionSupport {
	
	private int classid;
	private int worktime;
	private List<GraduationVO> root;
	
	@Autowired
	private ClassmngManager classmng;
	@Autowired
	private ContractManager contractmng;
	
	public String findSign(){
		root=classmng.findGraduation(classid,worktime);
		return SUCCESS;
	}
	
	public String endClassContract(){
		OaClass oaclass = classmng.findById(classid);
		oaclass.setState(0);
		classmng.update(oaclass);
		for(OaStudent stu : oaclass.getOaStudents()){
			for(OaContract con : stu.getOaContracts()){
				con.setState(0);
				contractmng.update(con);
			}
		}
		return SUCCESS;
	}
	
	public List<GraduationVO> getRoot() {
		return root;
	}
	public void setClassid(int classid) {
		this.classid = classid;
	}

	public void setClassmng(ClassmngManager classmng) {
		this.classmng = classmng;
	}

	public int getWorktime() {
		return worktime;
	}

	public void setWorktime(int worktime) {
		this.worktime = worktime;
	}

}
